package com.guigu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.mapper.PayDetailInfoMapper;
import com.guigu.mapper.ShopInfoMapper;
import com.guigu.mapper.SupplierSupplyOfGoodsMapper;
import com.guigu.mapper.WarehouseInfoMapper;
import com.guigu.pojo.PayDetailInfo;
import com.guigu.pojo.PayInfo;
import com.guigu.pojo.SupplierSupplyOfGoods;
import com.guigu.service.PayDetailInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayDetailInfoServiceimpl extends ServiceImpl<PayDetailInfoMapper, PayDetailInfo> implements PayDetailInfoService {
    @Autowired
    WarehouseInfoMapper warehouseInfoMapper;//仓库表
    @Autowired
    ShopInfoMapper shopInfoMapper;//商品表
    @Autowired
    SupplierSupplyOfGoodsMapper supplierSupplyOfGoodsMapper;//商品维护表

    //分页查询
    @Override
    public Page<PayDetailInfo> queryAll(PayDetailInfo payDetailInfo, Integer pageno, Integer pagesize) {
        QueryWrapper queryWrapper=new QueryWrapper<PayDetailInfo>();
        //条件查询
        //父id
        if (payDetailInfo.getPayId()!=null){
            queryWrapper.eq("pay_id",payDetailInfo.getPayId());
        }
        //仓库id
        if (payDetailInfo.getWarId()!=null){
            queryWrapper.eq("war_id",payDetailInfo.getWarId());
        }
        //商品维护id
        if (payDetailInfo.getSupplyOrderId()!=null){
            queryWrapper.eq("supply_orderId",payDetailInfo.getSupplyOrderId());
        }
        //删除状态
        if (payDetailInfo.getIsDelete()!=null){
            queryWrapper.eq("is_delete",payDetailInfo.getIsDelete());
        }
        Page<PayDetailInfo> page = this.page(new Page<PayDetailInfo>(pageno, pagesize), queryWrapper);
        //循环补全属性
        for(PayDetailInfo p : page.getRecords()){
            //获取仓库表
            p.setWarehouseInfo(warehouseInfoMapper.selectById(p.getWarId()));
            //获取商品维护表
            SupplierSupplyOfGoods supplierSupplyOfGoods=supplierSupplyOfGoodsMapper.selectById(p.getSupplyOrderId());
            supplierSupplyOfGoods.setShop(shopInfoMapper.selectById(supplierSupplyOfGoods.getGId()));
            p.setSupplierSupplyOfGoods(supplierSupplyOfGoods);
        }
        return page;
    }
}
